package com.kqkj.dyrule.marketing.utils;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 * 规则管理平台web系统模拟器
 */
public class RuleManagerPlatfromSimulator {

    public static void main(String[] args) throws Exception {
        insertRule();
    }
    //插入新规则到mysql
    public static void insertRule() throws Exception{
        String drlString = FileUtils.readFileToString(new File("rule_engine/src/main/resources/rules/demo1.drl"), "utf-8");
        String jsonString = FileUtils.readFileToString(new File("rule_engine/rules/rule1.json"), "utf-8");

        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://110.42.246.126:3306/dynamic_rule?useUnicode=true&characterEncoding=utf8", "root", "123456");

        PreparedStatement st = conn.prepareStatement("insert into dynamic_rule (rule_name,rule_condition_json,rule_controller_drl,rule_status,create_time,update_time,author) " +
                " values (?,?,?,?,?,?,?)");
        st.setString(1,"rule_1");
        st.setString(2,jsonString);
        st.setString(3,drlString);
        st.setString(3,"1");
        st.setString(3,"2021-05-12 16:41:00");
        st.setString(3,"2021-05-12 16:41:00");
        st.setString(3,"1");
        st.setString(3,"1");

        st.execute();
        st.close();
        conn.close();
    }


    //更新已存在的规则

    //删除规则

    //启用规则

    //听用规则
}
